qui(
    function (require, exports, module) {
        VOD.Player = (function () {
            var playOnePosition = {
                left: '',
                top: ''
            }
            var flashvars = {};
            var textArr = [];
            var params = {};
            params.scale = "noscale";
            params.salign = "tl";
            params.wmode = "transparent";
            params.swliveconnect = "true";
            params.allowfullscreen = "true";
            params.allowscriptaccess = "always";
            params.allownetworking = "all";
            params.bgcolor = "#000000";
            var player = {};
            player.swf = "http://www.iqiyi.com/player/20130702143439/expressInstall.swf";
            player.version = "10.0.0";
            player.liveEidtUrl = "/epg/swfs/liveEidt.swf";
            player.ScreenPrintUrl = "/epg/swfs/ScreenPrint.swf?20156291103";

            var settings = VOD.Dao.settings;
            // 左侧播放器
            function initLeftPlayer() {
                var attributes = {};
                attributes.id = "flash";
                attributes.pause = "暂停";
                swfobject.embedSWF(player.liveEidtUrl, "ppsLiveDiv", "100%", "300", player.version, player.swf, flashvars, params, attributes);
            }

            // 单张图片视频预览播放器
            function initPicPlayer() {
                var _attributes = {};
                _attributes.id = "flashOne";
                _attributes.pause = "暂停";
                swfobject.embedSWF(player.liveEidtUrl, "ppsLiveOneFrame", "100%", "100%", player.version, player.swf, flashvars, params, _attributes);
            }

// 起止帧精确化播放器
            function initFramePlayer() {
                var _attributes = {};
                _attributes.id = "accurateStartEndFrame";
                _attributes.pause = "暂停";
                params.scale = "Showall";
                swfobject.embedSWF(player.ScreenPrintUrl, "accurateStartEndDiv", "100%", "100%", player.version, player.swf, flashvars, params, _attributes);
            }

            //搭建js与flash互通的环境
            function thisMovie(movieName) {
                if (navigator.appName.indexOf("Microsoft") != -1) {
                    return window[movieName];
                } else {
                    return document[movieName];
                }
            }

            function shuffle(inputArr) {
                var valArr = [],
                    k = '';

                for (k in inputArr) { // Get key and value arrays
                    if (inputArr.hasOwnProperty(k)) {
                        valArr.push(inputArr[k]);
                    }
                }
                valArr.sort(function () {
                    return 0.5 - Math.random();
                });

                return valArr;
            }

            function playAll(allList) {
                var text = {};
                text.textContent = '';
                textArr.length = 0;
                var k = {};
                for (k in allList.list) {
                    textArr.push(allList.list[k].url);
                }
                text.textContent = textArr.join('\r\n');
                thisMovie('flash').load(JSON.stringify(allList));
            }

            function playOne(allList) {
                var text = {};
                text.textContent = '';
                textArr.length = 0;
                var k = {};
                for (k in allList.list) {
                    textArr.push(allList.list[k].url);
                }

                text.textContent = textArr.join('\r\n');

                thisMovie('flashOne').load(JSON.stringify(allList));
                $("#play-one").css({
                    top: playOnePosition.top,
                    left: playOnePosition.left
                });
            }

            function updatePosition(options) {
                playOnePosition.left = options.left;
                playOnePosition.top = options.top;
            }

            function initPlayer() {
                initLeftPlayer();
                initPicPlayer();
                initFramePlayer();
            }

            //播放功能
            function view(viewTime) {
                var listUrl = VOD.Dao.getDotData().listUrl;
                //从刘志红那里取json列表
                $.get(listUrl, {
                    'key' : VOD.Dao.settings.taskid,
                    'from_client' : true,
                    'index' : viewTime,
                    'type' : 0,
                    'offset' : 100
                }, function (data) {
                    $('#allList').data(data);
                    playAll(data);
                }, 'json');
                //传给王鹏
            }

            //播放1帧
            function viewOne(viewTime) {
                //从刘志红那里取json列表
                var listUrl = VOD.Dao.getDotData().listUrl;
                $.get(listUrl, {
                    'key': VOD.Dao.settings.taskid,
                    'from_client': true,
                    'index': viewTime,
                    'type': 0,
                    'offset': 1
                }, function (data) {
                    $('#allList').data(data);
                    playOne(data);
                }, 'json');
                //传给王鹏
            }

            function splitData(stime, etime, needRemoveDelData) {
                stime = parseInt(stime);
                etime = parseInt(etime);
                var settings = VOD.Dao.settings;
                settings.subData = [];
                var needDatas = [];
                for (i = stime; i <= etime; i++) {
                    needDatas.push(i);
                }
                //console.log(needDatas);
                //console.log(delList);
                if (needRemoveDelData && settings.delList.length) {
                    $.each(settings.delList, function (k, v) {
                        v = parseInt(v);
                        if (stime <= v && v <= etime) {
                            for (var i = 0; i < needDatas.length; i++) { //删除v的元素
                                if (needDatas[i] == v) {
                                    needDatas.splice(i, 1);
                                    break;
                                }
                            }
                        }
                    })
                }
                settings.subData = needDatas;
                //console.log(subData);
            }

            function review() {
                if (!settings.subData.length) {
                    //alert('请先打点,再预览!');
                    VOD.Plugin.tips("error", '请先打点,再预览!');
                    return false;
                }
                var reviewData = {
                    'list': []
                };
                //console.log(subData);
                $.each(settings.subData, function (k, v) {
                    var src = $('#img-' + v).attr('src');
                    if (!src) {
                        //alert('数据为空不能预览!');
                        return false;
                    }
                    reviewData.list.push( {url: src.replace(/jpg/g, "flv"),name: k+"" });
                })

                playAll(reviewData);
            }

            //打好的点预览
            var reviewOne = function (s, e, vType) {
                var reviewOneData = {
                    'list': []
                };
                s = parseInt(s);
                e = parseInt(e);
                var src , flv, obj;
                for (var i = s; i <= e; i++) {
                    if (settings.delList.length && vType != "删除") {
                        var isNeed = true;
                        for (var j = 0; j <= settings.delList.length; j++) {
                            var v = settings.delList[j];
                            if (i == v) {
                                isNeed = false;
                            }
                        }
                        if (isNeed) {
                            src = $('#img-' + i).attr('src');
                            obj = {url: src.replace(/jpg/g, "flv"),name: i+"" }
                            reviewOneData.list.push(obj);
                        }
                    } else {
                        src = $('#img-' + i).attr('src');
                        obj = {url: src.replace(/jpg/g, "flv"),name: i+"" }
                        reviewOneData.list.push(obj);
                    }
                }
                //console.log(reviewOneData);
                playAll(reviewOneData);
            }

            function nofind(img_url){
                var img=event.srcElement;
                img.src=img_url;
            }

            return {
                initPlayer: initPlayer,
                playAll: playAll,
                playOne: playOne,
                updatePosition: updatePosition,
                viewOne: viewOne,
                view:view,
                nofind:nofind,
                splitData:splitData,
                review:review,
                reviewOne:reviewOne
            }
        })()
    }
);